define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'business/visit/index',
                    add_url: 'business/visit/add',
                    edit_url: 'business/visit/edit',
                    del_url: 'business/visit/del',
                    table: 'business_visit',
                }
            });
            var VisitTable = $("#VisitTable");

            // 初始化表格
            VisitTable.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                toolbar: '#VisitToolbar',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), sortable: true },
                        {
                            field: 'content', title: __('Vcontent'), operate: 'LIKE',
                            // 限制字符长度，超出用省略号显示
                            formatter: function (value, row, index, field) {
                                return "" + value + "";
                            },
                            cellStyle: function (value, row, index, field) {
                                return {
                                    css: {
                                        "min-width": "120px",
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width": "300px"
                                    }
                                }
                            }
                        },
                        { field: 'business.nickname_text', title: __('Nickname'), operate: 'LIKE' },
                        { field: 'admin.nickname', title: __('AdminName'), operate: 'LIKE' },
                        { field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', },
                        { field: 'operate', title: __('Operate'), table: VisitTable, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });
           
            // 为表格绑定事件
            Table.api.bindevent(VisitTable);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});